// index.js
// import Toast from 'vant-weapp/toast/toast';
const util = require('../../utils/util.js');
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'


Page({
  data: {
    loadingHidden: true,
    winWidth:0, 
    winHeight:0, 
    sleft:0,
    nav_type: 0,
    calDate:"请选择要计算的年月",
    nowYear:"",
    index: 0,
    tabCur:0,
    activeVantTab:0,
    tabs: [{
      name: '工资薪金',
      id: 0
    },
    {
      name: '劳务所得',
      id: 1
    },
    // {
    //   name: '个人经营所得',
    //   id: 2
    // },
    {
      name: '稿酬所得',
      id: 3
    },
    {
      name: '特许权使用费',
      id: 4
    }
  ],
    userInfo: {
      avatarUrl: defaultAvatarUrl,
      nickName: '',
    },
    hasUserInfo: false,
    canIUseGetUserProfile: wx.canIUse('getUserProfile'),
    canIUseNicknameComp: wx.canIUse('input.type.nickname'),
    salary:"",
    person:"",
    securate:"",
    Gongjijing:"",
    // secondSecurity:null,
    another:"",
    salaryAfter:"",
    // secondGjj:null,
    // secondIndexS:2,
    // secondIndexG:0,
  // 劳动报酬
    baochouBefore:null,
    baochouCalWay:"1",
    baochouRate:20,
    baochouRateAfter:"0.00",
    kouchushu:"0",
    laowutax:"0.00",
    ratebefore:"0.00",
    incomeAfterCalWay:"1",
    incomeAfterRate:"20",
    incomeSusuanAfter:"0",
    income:"0.00",
    laowutaxFantui:"0.00",
  // 稿酬变量
    royaltiesAfterRate:"0.00",
    royaltiesRate:"20",
    sunsuanForRoyalties:"0",
    royalties:null,
    royaltiesTax:"0.00",
    royaltiesCalWay:"1" ,

    fantuiRoyaltiesBeforeRate:"0.00",
    fantuiSusuanNum:"0",
    fantuiRoyaltiesRate:"20",
    royaltiesFantui:null,
    fantuiRoyaltiesTax:"0.00",
    fantuiRoyaltiesCalWay:"1",
    //特许权使用费
    franchiseAfterRate:"0.00",
    franchiseRate:"20",
    sunsuanForFranchise:"0",
    franchise:null,
    franchiseTax:"0.00",
    franchiseCalWay:"1" ,

    fantuiFranchiseBeforeRate:"0.00",
    fantuiFranchiseSusuanNum:"0",
    fantuiFranchiseRate:"20",
    franchiseFantui:null,
    fantuiFranchiseTax:"0.00",
    fantuiFranchiseCalWay:"1",

    //年底汇算变量
    annualSalary:"",
    yearEndBonus:"",
    annualBaochou:"",
    yearEndBonusWayChange:{checkA:false,checkB:true},
    annualSecurate:"",
    annualGongjijing:"",
    annualZhuanXiang:"",
    annualRoyalties:"",
    annualFranchise:"",
    annualAnother:"",
    calYear:'请选择计算年份',
    hidden:true,
    nocancel:false,
    touX: 0,  // 拖动后的X坐标
    touY: 0, // 拖动后的Y坐标
    x: 340,//定位X轴位置
    y: 40, //定位Y轴位置
  },

  serviceClick(e){
    this.setData({hidden:false})
  }, 
  bindchange(e){
    this.setData({ 
      touX: e.detail.x,
      touY: e.detail.y
      })
    //  console.log(e.detail)
  },
  bindtouchend(e){
    let _this = this;
    // console.log('停止',_this.data.touY,e)
    // setTimeout(function(){
      if(_this.data.touX + 50 > _this.data.windowWidth && _this.data.touY+50 < _this.data.windowHeight){ // 移动右边超过了边距
        _this.setData({ 
          x: _this.data.windowWidth - 25,
          y: e.changedTouches[0].pageY-20
          // y: Number(JSON.parse(JSON.stringify(_this.data.touY)))
        })
      }

      if(_this.data.touX + 50 < _this.data.windowWidth && _this.data.touY+50 < _this.data.windowHeight){  // 没有超过的时候，自动在右边
        _this.setData({ 
          x: _this.data.windowWidth - 50,
          y: e.changedTouches[0].pageY-20
          // y: Number(JSON.parse(JSON.stringify(_this.data.touY)))
        })
      }

      if(_this.data.touY+50 > _this.data.windowHeight){ // 滑到底部的时候
        _this.setData({
          x: _this.data.windowWidth-50, 
          y: _this.data.windowHeight- 100
          // y: Number(JSON.parse(JSON.stringify(_this.data.touY)))
        })
      }
    // },1000)
  }, 

  cancel: function(){
    this.setData({
         hidden: true
    });
},

/**
 *  点击确认
 */
confirm: function(){
    this.setData({
      hidden: true
    })
  },
  
  //选择条目
  tabSelect(e) {
    const that = this;
    if (that.data.tabCur === e.target.dataset.current){
        return false;
    }else{
      this.setData({
        tabCur: e.currentTarget.dataset.id,
        scrollLeft: (e.currentTarget.dataset.id - 2) * 200
      })
    }
  },

  bindChange(e) {
    var that = this;
    that.setData({ tabCur: e.detail.current});
    },

  onClickVantTabs(e){
    var that = this;
    that.setData({activeVantTab: e.detail.index});
    // console.log(this.data.activeVantTab);
  },

  getPercentage(e){
    var month = this.data.calDate;
    //说明用户都没选计算月份就开始填写了
    if(month.indexOf('-') == -1){
      wx.showToast({  
        title: '请选择计算月份!', // 提示的内容  
        icon: 'error' // 图标，成功时显示对号图标  
      });
      return;
    }
    wx.navigateTo({
      url: "/pages/percentage/percentage?calDate="+ month
    });
  },


  getRate(e){
    // index + 1就是实际月份
    var month = this.data.calDate;
    //说明用户都没选计算月份就开始填写了
    if(month.indexOf('-') == -1){
      wx.showToast({  
        title: '请选择计算月份!', // 提示的内容  
        icon: 'error' // 图标，成功时显示对号图标  
      });
      return;
    }
    wx.navigateTo({
      url: "/pages/rate/rate?calDate=" + month
    });
  },

  getHousingFund(){
    var month = this.data.calDate;
    //说明用户都没选计算月份就开始填写了
    if(month.indexOf('-') == -1){
      wx.showToast({  
        title: '请选择计算月份!', // 提示的内容  
        icon: 'error' // 图标，成功时显示对号图标  
      });
      return;
    }
    wx.navigateTo({
      url: "/pages/housingFund/housingFund?calDate="+month
    });
  },

  getPersonInfo(e){
    var month = this.data.calDate;
    //说明用户都没选计算月份就开始填写了
    if(month.indexOf('-') == -1){
      wx.showToast({  
        title: '请选择计算月份!', // 提示的内容  
        icon: 'error' // 图标，成功时显示对号图标  
      });
      return;
    }
    console.log(month);
    wx.navigateTo({
      url: "/pages/person/person?calDate="+month,
      events:{
        acceptDataFromOpenedPage: function(data) {
          console.log(data)
        }
      }
    });
  },
  getAnotherValue(e){
    var month = this.data.calDate;
    //说明用户都没选计算月份就开始填写了
    if(month.indexOf('-') == -1){
      wx.showToast({  
        title: '请选择计算月份!', // 提示的内容  
        icon: 'error' // 图标，成功时显示对号图标  
      });
      return;
    }
    console.log(month);
    wx.navigateTo({
      url: "/pages/another/another?calDate="+month,
      events:{
        acceptDataFromOpenedPage: function(data) {
          console.log(data)
        }
      }
    });
  },

  getPersonValue(e){
    this.setData({person:e.detail.value});
  },

  onInputChange(e) {
    const nickName = e.detail.value
    const { avatarUrl } = this.data.userInfo
    this.setData({
      "userInfo.nickName": nickName,
      hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
    })
  },

  bindPickerChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      calDate: e.detail.value
    })
  },

  //*********************************以下是年度汇算的方法****************** */
  onAnnualSalary(e){
    var value = e.detail.value;
    if(/^(0|[1-9][0-9]*)$/.test(value) || /^([1-9][0-9]*\.)$/.test(value) || /^([1-9][0-9]*)+(\.[0-9]{1,2})?$/.test(value)){
        this.setData({annualSalary:value});
    }else{
       wx.showToast({
         title: '请正确输入年度工资！\r\n(仅数字，最多2位小数)',
         icon:'none'
       });
       this.setData({annualSalary:''});
    }
  },

  onYearEndBonus(e){
    var value = e.detail.value;
    if(/^(0|[1-9][0-9]*)$/.test(value) || /^([1-9][0-9]*\.)$/.test(value) || /^([1-9][0-9]*)+(\.[0-9]{1,2})?$/.test(value)){
        this.setData({yearEndBonus:value});
    }else{
       wx.showToast({
         title: '请正确输入年终奖金额！\r\n(仅数字，最多2位小数)',
         icon:'none'
       });
       this.setData({yearEndBonus:''});
    }
  },

  onAnnualBaochou(e){
    var value = e.detail.value;
    if(/^(0|[1-9][0-9]*)$/.test(value) || /^([1-9][0-9]*\.)$/.test(value) || /^([1-9][0-9]*)+(\.[0-9]{1,2})?$/.test(value)){
        this.setData({annualBaochou:value});
    }else{
       wx.showToast({
         title: '请正确输入劳务报酬！\r\n(仅数字，最多2位小数)',
         icon:'none'
       });
       this.setData({annualBaochou:''});
    }
  },

  onAnnualRoyalties(e){
    var value = e.detail.value;
    if(/^(0|[1-9][0-9]*)$/.test(value) || /^([1-9][0-9]*\.)$/.test(value) || /^([1-9][0-9]*)+(\.[0-9]{1,2})?$/.test(value)){
        this.setData({annualRoyalties:value});
    }else{
       wx.showToast({
         title: '请正确输入劳务报酬！\r\n(仅数字，最多2位小数)',
         icon:'none'
       });
       this.setData({annualRoyalties:''});
    }
  },

  onAnnualFranchise(e){
    var value = e.detail.value;
    if(/^(0|[1-9][0-9]*)$/.test(value) || /^([1-9][0-9]*\.)$/.test(value) || /^([1-9][0-9]*)+(\.[0-9]{1,2})?$/.test(value)){
        this.setData({annualFranchise:value});
    }else{
       wx.showToast({
         title: '请正确输入劳务报酬！\r\n(仅数字，最多2位小数)',
         icon:'none'
       });
       this.setData({annualFranchise:''});
    }
  },

  bindCalYearChange(e){
    var that = this;
    that.setData({calYear:e.detail.value});
  },

  calYearEndBonusWayChange(e){
    var val = e.detail.value;
    var calWay = this.data.yearEndBonusWayChange;
    if(val === '1'){
      calWay.checkA = true;
      calWay.checkB = false;
    }else{
      calWay.checkA = false;
      calWay.checkB = true;
    }
   this.setData({yearEndBonusWayChange:calWay})
  },
  
  // 年度社保计算跳转
  getAnnualPercentage(e){
    var calYear = this.data.calYear;
    //说明用户都没选计算年份就开始填写了
    if(calYear.length > 4){
      wx.showToast({  
        title: '先选年份再计算!', // 提示的内容
        icon: 'error' // 图标，成功时显示对号图标
      });
      return;
    }
    wx.navigateTo({
      url: "/pages/annualPercentage/annualPercentage?calYear="+calYear,
      events:{
        acceptDataFromOpenedPage: function(data) {
          console.log(data)
        }
      }
    });
  },

  // 年度公积金计算
  getAnnualHousingFund(e){
    var calYear = this.data.calYear;
    //说明用户都没选计算年份就开始填写了
    if(calYear.length > 4){
      wx.showToast({  
        title: '先选年份再计算!', // 提示的内容
        icon: 'error' // 图标，成功时显示对号图标
      });
      return;
    }
    wx.navigateTo({
      url: "/pages/annualHousingFund/annualHousingFund?calYear="+calYear,
      events:{
        acceptDataFromOpenedPage: function(data) {
          console.log(data)
        }
      }
    });
  },

  // 年度专项附加扣除
  getAnnualZhuanXiang(e){
    var calYear = this.data.calYear;
    //说明用户都没选计算年份就开始填写了
    if(calYear.length  > 4){
      wx.showToast({  
        title: '先选年份再计算!', // 提示的内容
        icon: 'error' // 图标，成功时显示对号图标
      });
      return;
    }
    wx.navigateTo({
      url: "/pages/annualPerson/annualPerson?calYear="+calYear,
      events:{
        acceptDataFromOpenedPage: function(data) {
          console.log(data)
        }
      }
    });
  },

  // 计算年度扣除
  getAnnualAnother(e){
    var calYear = this.data.calYear;
    //说明用户都没选计算月份就开始填写了
    if(calYear.length  > 4){
      wx.showToast({  
        title: '先选年份再计算!', // 提示的内容
        icon: 'error' // 图标，成功时显示对号图标
      });
      return;
    }
    wx.navigateTo({
      url: "/pages/annualAnother/annualAnother?calYear="+calYear,
      events:{
        acceptDataFromOpenedPage: function(data) {
          console.log(data)
        }
      }
    });
  },

  //*********************************以下是劳务报酬汇算的方法****************** */

  //变换计算方式，重新计算结果
  getBaochouCalWay(e){
    // this.setData({baochouBefore:""});
    this.setData({baochouCalWay:e.detail.value})
  },
  
  clearInputBaochou(e){
    this.setData({baochouBefore:''});
    this.setData({kouchushu:"0"});
    this.setData({baochouRate:"20"});
    this.setData({laowutax:'0.00'});
    this.setData({baochouRateAfter:'0.00'});
  },
  clearInputIncome(e){
    this.setData({shuiHouIncome:''});
    this.setData({incomeAfterRate:"3"});
    this.setData({incomeSusuanAfter:"0"});
    this.setData({laowutaxFantui:'0.00'});
    this.setData({income:'0.00'});
  },

  calJuMingBaoChou:function(baochou1){
    var baochou = baochou1
    // 超过4000，减除20%算收入额，来计算预扣预缴个税
    if(baochou1 > 4000){
      baochou = baochou1 * 0.8;
      // 超过5W的部分收取40%的个税
      if(baochou > 50000){
        this.setData({kouchushu:"7000"});
        this.setData({baochouRate:"40"});
        var tax = baochou * 0.4 - 7000;
        this.setData({laowutax:tax.toFixed(2)});
        console.log(this.data.laowutax);
        return;
      }
      // 超过2W小于5W的收入
      else if(baochou <= 50000 && baochou > 20000){
        this.setData({kouchushu:"2000"});
        this.setData({baochouRate:"30"});
        var tax = baochou * 0.3 - 2000;
        this.setData({laowutax:tax.toFixed(2)});
        console.log(this.data.laowutax);
        return;
      }else{
        // 小于20000的收入
        this.setData({kouchushu:"0"});
        this.setData({baochouRate:"20"});
        var tax = baochou * 0.2;
        this.setData({laowutax:tax.toFixed(2)});
        console.log("小于20000的收入"+this.data.laowutax);
        return;
      }
    }else{
      // 当劳务报酬小于4000元，减除800元然后计算
      baochou = baochou1 - 800;
      // 收入小于减除费用，就不扣税了。
      if(baochou <= 0){
        this.setData({laowutax:"0.00"});
        this.setData({baochouRate:"20"});
        this.setData({kouchushu:"0"});
        // console.log(this.data.laowutax);
        return;
      }
      //大于800元的部分减除800后，再收20%的税
      var value = (baochou * 0.2).toFixed(2)
      this.setData({laowutax:value.toString()});
      console.log(this.data.laowutax);
    }
  },

  calFeiJuMingBaoChou:function(baochou){
    //console.log(baochou);
    // 非居民人员劳务收入减除20%作为应纳税额
    baochou = baochou * 0.8;
    if(baochou <= 3000){
        this.setData({kouchushu:"0"});
        this.setData({baochouRate:"3"});
        var tax = (baochou * 0.03).toFixed(2) ;
        this.setData({laowutax:tax.toString()});
        console.log(this.data.laowutax);
        return;
    }
    if(baochou > 3000 && baochou <= 12000){
        this.setData({kouchushu:"210"});
        this.setData({baochouRate:"10"});
        var tax = (baochou * 0.1 - 210).toFixed(2) ;
        this.setData({laowutax:tax.toString()});
        console.log(this.data.laowutax);
        return;
    }
    if(baochou > 12000 && baochou <= 25000){
        this.setData({kouchushu:"1410"});
        this.setData({baochouRate:"20"});
        var tax = (baochou * 0.2 - 1410).toFixed(2);
        this.setData({laowutax:tax.toString()});
        console.log(this.data.laowutax);
        return;
    }
    if(baochou > 25000 && baochou <= 35000){
        this.setData({kouchushu:"2660"});
        this.setData({baochouRate:"25"});
        var tax = (baochou * 0.25 - 2660).toFixed(2);
        this.setData({laowutax:tax.toString()});
        console.log(this.data.laowutax);
        return;
    }
    if(baochou > 35000 && baochou <= 55000){
      this.setData({kouchushu:"4410"});
      this.setData({baochouRate:"30"});
      var tax = (baochou * 0.3 - 4410).toFixed(2);
      this.setData({laowutax:tax.toString()});
      console.log(this.data.laowutax);
      return;
    }
    if(baochou > 55000 && baochou <= 80000){
      this.setData({kouchushu:"7160"});
      this.setData({baochouRate:"35"});
      var tax = (baochou * 0.35 - 7160).toFixed(2);
      this.setData({laowutax:tax.toString()});
      console.log(this.data.laowutax);
      return;
    }
    else{
      this.setData({kouchushu:"15160"});
      this.setData({baochouRate:"45"});
      var tax = (baochou * 0.45 - 15160).toFixed(2);
      this.setData({laowutax:tax.toString()});
      console.log(this.data.laowutax);
      return;
    }
  },
  // 正算税收计算方式获取
  getBaochouCalWay(e){
     this.setData({baochouCalWay:e.detail.value});
  },

  //计算居民劳务收入与非居民劳务收入入口
  getbaochou:function(value){
    if(/^(0|[1-9][0-9]*)$/.test(value) || /^([1-9][0-9]*\.)$/.test(value) || /^([1-9][0-9]*)+(\.[0-9]{1,2})?$/.test(value)){
      this.setData({baochouBefore:value});
      var baochou = Number.parseFloat(value);
      var type = this.data.baochouCalWay;
      if(type == "1"){
        // 计算居民劳务收入
        this.calJuMingBaoChou(baochou);
      }else{
        // 计算非居民劳务收入
        this.calFeiJuMingBaoChou(baochou);
      }
      var shuiHou = (baochou - this.data.laowutax).toFixed(2);
      this.setData({baochouRateAfter:shuiHou.toString()});
      console.log("税后收入"+this.data.baochouRateAfter)
    }else{
       wx.showToast({
         title: '请正确输入税前收入！\r\n(仅数字，最多2位小数)',
         icon:'none'
       });
       this.setData({baochouRateAfter:"0.00"});
       this.setData({laowutax:"0.00"});
       this.setData({kouchushu:"0"})
       //this.setData({laowutax:"0.00"})
       return;
    }
  },
  onGetBaochouBefore(e){
    var value = e.detail.value;
    this.getbaochou(value);
  },

  //反推居民劳务报酬的税前
  fantuiJuMingBaoChou:function(incomeValue){
    // 税后小于800，税额为0
    if(incomeValue <= 800){
        this.setData({income:incomeValue.toString()});
        this.setData({laowutaxFantui:"0.00"});
        this.setData({incomeAfterRate:"20"});
        this.setData({incomeSusuanAfter:"0"});
        return;
    }
    //小于4000的减除费用为800，税率20%
    if(incomeValue <= 3200 && incomeValue > 800){
      var before = (incomeValue - 160) / 0.8;
      before = before.toFixed(2);
      this.setData({income:before.toString()});
      var tax = (before - incomeValue).toFixed(2);
      this.setData({laowutaxFantui:tax.toString()});
      this.setData({incomeAfterRate:"20"});
      this.setData({incomeSusuanAfter:"0"});
      return;
    }
    //大于4000小于20000，速算扣除0，减除费用20%，税率20%
    if(incomeValue > 3200 && incomeValue <= 25000){
      var before = incomeValue / (1 - 0.16)
      before = before.toFixed(2);
      this.setData({income:before.toString()});
      var tax = (before - incomeValue).toFixed(2);
      this.setData({laowutaxFantui:tax.toString()});
      this.setData({incomeAfterRate:"20"});
      this.setData({incomeSusuanAfter:"0"});
      return;
    }
    //大于20000小于50000，速算扣除数2000，税率30%，减除费用20%
    if(incomeValue > 25000 && incomeValue <= 62500){
      var before = (incomeValue - 2000) / (1 - 0.24)
      before = before.toFixed(2);
      this.setData({income:before.toString()});
      var tax = (before - incomeValue).toFixed(2);
      this.setData({laowutaxFantui:tax.toString()});
      this.setData({incomeAfterRate:"30"});
      this.setData({incomeSusuanAfter:"2000"});
      return;
    }else{
      var before = (incomeValue - 7000) / (1 - 0.32)
      before = before.toFixed(2);
      this.setData({income:before.toString()});
      var tax = (before - incomeValue).toFixed(2);
      this.setData({laowutaxFantui:tax.toString()});
      this.setData({incomeAfterRate:"40"});
      this.setData({incomeSusuanAfter:"7000"});
    }
  },

  //反推非居民个人的劳务报酬税前工资
  fantuiFeiJuMingBaoChou:function(income_fjm){
    if(income_fjm <= 3660){
      var before = income_fjm / (1 - 0.024);
      before = before.toFixed(2);
      this.setData({income:before.toString()});
      var tax = (before - income_fjm).toFixed(2);
      this.setData({laowutaxFantui:tax.toString()});
      this.setData({incomeAfterRate:"3"});
      this.setData({incomeSusuanAfter:"0"});
      return;
    }
    if(income_fjm > 3660 && income_fjm <= 14010){
      var before = (income_fjm - 210 ) / (1 - 0.08);
      before = before.toFixed(2);
      this.setData({income:before.toString()});
      var tax = (before - income_fjm).toFixed(2);
      this.setData({laowutaxFantui:tax.toString()});
      this.setData({incomeAfterRate:"10"});
      this.setData({incomeSusuanAfter:"210"});
      return;
    }
    if(income_fjm > 14010 && income_fjm <= 25750){
      var before = (income_fjm - 1410 ) / (1 - 0.16);
      before = before.toFixed(2);
      this.setData({income:before.toString()});
      var tax = (before - income_fjm).toFixed(2);
      this.setData({laowutaxFantui:tax.toString()});
      this.setData({incomeAfterRate:"20"});
      this.setData({incomeSusuanAfter:"1410"});
      return;
    }
    if(income_fjm > 25750 && income_fjm <= 35250){
      var before = (income_fjm - 2660 ) / (1 - 0.2);
      before = before.toFixed(2);
      this.setData({income:before.toString()});
      var tax = (before - income_fjm).toFixed(2);
      this.setData({laowutaxFantui:tax.toString()});
      this.setData({incomeAfterRate:"25"});
      this.setData({incomeSusuanAfter:"2660"});
      return;
    }
    if(income_fjm > 35250 && income_fjm <= 53750){
      var before = (income_fjm - 4410 ) / (1 - 0.24);
      before = before.toFixed(2);
      this.setData({income:before.toString()});
      var tax = (before - income_fjm).toFixed(2);
      this.setData({laowutaxFantui:tax.toString()});
      this.setData({incomeAfterRate:"30"});
      this.setData({incomeSusuanAfter:"4410"});
      return;
    }
    if(income_fjm > 53750 && income_fjm <= 75000){
      var before = (income_fjm - 7160 ) / (1 - 0.28);
      before = before.toFixed(2);
      this.setData({income:before.toString()});
      var tax = (before - income_fjm).toFixed(2);
      this.setData({laowutaxFantui:tax.toString()});
      this.setData({incomeAfterRate:"35"});
      this.setData({incomeSusuanAfter:"7160"});
      return;
    }else{
      var before = ( income_fjm - 15160 ) / (1 - 0.36);
      before = before.toFixed(2);
      this.setData({income:before.toString()});
      var tax = (before - income_fjm).toFixed(2);
      this.setData({laowutaxFantui:tax.toString()});
      this.setData({incomeAfterRate:"45"});
      this.setData({incomeSusuanAfter:"15160"});
      return;
    }
  },

  //反推税前劳务报酬的计算入口
  getShuiHouIncome(e){
    var value = e.detail.value;
    if(/^(0|[1-9][0-9]*)$/.test(value) || /^([1-9][0-9]*\.)$/.test(value) || /^([1-9][0-9]*)+(\.[0-9]{1,2})?$/.test(value)){
      var income = Number.parseFloat(value);
      var type = this.data.incomeAfterCalWay;
      if(type == "1"){
        // 计算居民劳务收入
        this.fantuiJuMingBaoChou(income);
      }else{
        // 计算非居民劳务收入
        this.fantuiFeiJuMingBaoChou(income);
      }
    }else{
      wx.showToast({
        title: '请正确输入税后收入！\r\n(仅数字，最多2位小数)',
        icon:'none'
      });
      this.setData({income:"0.00"});
      this.setData({laowutaxFantui:"0.00"});
      return;
   }
  },
  // 获取反推劳务报酬的计算方式
  onGetBaochouAfterWay(e){
    this.setData({incomeAfterCalWay:e.detail.value});
  },
/***********************************稿酬的计算与页面响应************************* */
  // 计算居民个人稿酬预扣预缴个税
  calJuMingRoyalties:function(InputValue){
    var tempValue = InputValue;
    if(InputValue <= 4000){
      tempValue = tempValue - 800;
      if(tempValue <= 0){
        this.setData({royaltiesTax:"0.00"});
        this.setData({royaltiesAfterRate:InputValue.toString()});
        return;
      }else{
        // 减除费用后减按70%为应纳税额,税率20%
        var tax = (tempValue * 0.7 * 0.2).toFixed(2);
        this.setData({royaltiesTax:tax.toString()});
        return;
      }
    }else{
      var tax = (tempValue * 0.8 * 0.7 * 0.2).toFixed(2);
      this.setData({royaltiesTax:tax.toString()});
      return;
    }
  },

  // 计算非居民个人稿酬所得预扣预缴个税
  calFeiJuMingRoyalties:function(InputValue){
    // 稿酬减按70%
    var baochou = InputValue * 0.8 * 0.7;
    var tax = 0
    if(baochou <= 3000){
        this.setData({sunsuanForRoyalties:"0"});
        this.setData({royaltiesRate:"3"});
        tax = (baochou * 0.03).toFixed(2) ;
        //console.log(this.data.laowutax);
    }
    else if(baochou > 3000 && baochou <= 12000){
        this.setData({sunsuanForRoyalties:"210"});
        this.setData({royaltiesRate:"10"});
        tax = (baochou * 0.1 - 210).toFixed(2) ;
        // console.log(this.data.laowutax);
    }
    else if(baochou > 12000 && baochou <= 25000){
        this.setData({sunsuanForRoyalties:"1410"});
        this.setData({royaltiesRate:"20"});
        tax = (baochou * 0.2 - 1410).toFixed(2);
        // console.log(this.data.laowutax);
    }
    else if(baochou > 25000 && baochou <= 35000){
        this.setData({sunsuanForRoyalties:"2660"});
        this.setData({royaltiesRate:"25"});
       tax = (baochou * 0.25 - 2660).toFixed(2);
    }
    else if(baochou > 35000 && baochou <= 55000){
      this.setData({sunsuanForRoyalties:"4410"});
      this.setData({royaltiesRate:"30"});
      tax = (baochou * 0.3 - 4410).toFixed(2);
    }
    else if(baochou > 55000 && baochou <= 80000){
      this.setData({sunsuanForRoyalties:"7160"});
      this.setData({royaltiesRate:"35"});
      tax = (baochou * 0.35 - 7160).toFixed(2);
    }
    else{
      this.setData({sunsuanForRoyalties:"15160"});
      this.setData({royaltiesRate:"45"});
      tax = (baochou * 0.45 - 15160).toFixed(2);
    }
    this.setData({royaltiesTax:tax.toString()});
      // console.log(this.data.laowutax);
    return;
  },

  // 计算税后稿酬所得
  onGetRoyaltiesAfterRate(e){
    var value = e.detail.value;
    if(/^(0|[1-9][0-9]*)$/.test(value) || /^([1-9][0-9]*\.)$/.test(value) || /^([1-9][0-9]*)+(\.[0-9]{1,2})?$/.test(value)){
      this.setData({royalties:value});
      var input = Number.parseFloat(value);
      var type = this.data.royaltiesCalWay;
      if(type == "1"){
        // 计算居民劳务收入
        this.calJuMingRoyalties(input);
      }else{
        // 计算非居民劳务收入
        this.calFeiJuMingRoyalties(input);
      }
      var shuiHou = (input - this.data.royaltiesTax).toFixed(2);
      this.setData({royaltiesAfterRate:shuiHou.toString()});
      // console.log("税后稿酬"+this.data.baochouRateAfter)
    }else{
       wx.showToast({
         title: '请正确输入税前收入！\r\n(仅数字，最多2位小数)',
         icon:'none'
       });
       this.setData({royaltiesAfterRate:"0.00"});
       this.setData({royaltiesTax:"0.00"}); 
       this.setData({royalties:''});
       this.setData({sunsuanForRoyalties:"0"});
       this.setData({royaltiesRate:"20"})
       return;
    }
  },

  // 稿酬计算单选框方法
  onGetRoyaltieCalWay(e){
    this.setData({royaltiesCalWay:e.detail.value});
  },

  // 反推部分单选框的绑定函数
  onGetFantuiRoyaltiesCalWay(e){
    this.setData({fantuiRoyaltiesCalWay:e.detail.value});
  },

  // 反推计算居民个人税前稿酬
  calJuMingFantuiRoyalties:function(InputValue){
    // 小于800零税
    if(InputValue <= 800){
      this.setData({fantuiRoyaltiesBeforeRate:InputValue.toString()});
      this.setData({fantuiRoyaltiesTax:"0.00"});
      this.setData({fantuiRoyaltiesRate:"20"});
      this.setData({fantuiSusuanNum:"0"});
      return;
    }
    //小于4000的减除费用为800，税率20%
    if(InputValue <= 3552 && InputValue > 800){
      var before = (InputValue - 112) / 0.86;
      before = before.toFixed(2);
      this.setData({fantuiRoyaltiesBeforeRate:before.toString()});
      var tax = (before - InputValue).toFixed(2);
      this.setData({fantuiRoyaltiesTax:tax.toString()});
      this.setData({fantuiRoyaltiesRate:"20"});
      this.setData({fantuiSusuanNum:"0"});
      return;
    }
    //大于4000，速算扣除0，减除费用20%，减按70%，税率20%
    else{
      var before = InputValue / (1 - 0.112)
      before = before.toFixed(2);
      this.setData({fantuiRoyaltiesBeforeRate:before.toString()});
      var tax = (before - InputValue).toFixed(2);
      this.setData({fantuiRoyaltiesTax:tax.toString()});
      this.setData({fantuiRoyaltiesRate:"20"});
      this.setData({fantuiSusuanNum:"0"});
      return;
    }
  },

  calFeiJuMingFantuiRoyalties:function(InputValue){
    if(InputValue <= 5357.14){
      var before = InputValue / (1 - 0.0168);
      before = before.toFixed(2);
      this.setData({fantuiRoyaltiesBeforeRate:before.toString()});
      var tax = (before - InputValue).toFixed(2);
      this.setData({fantuiRoyaltiesTax:tax.toString()});
      this.setData({fantuiRoyaltiesRate:"3"});
      this.setData({fantuiSusuanNum:"0"});
      return;
    }
    if(InputValue > 5357.14 && InputValue <= 21428.57){
      var before = (InputValue - 210 ) / (1 - 0.056);
      before = before.toFixed(2);
      this.setData({fantuiRoyaltiesBeforeRate:before.toString()});
      var tax = (before - InputValue).toFixed(2);
      this.setData({fantuiRoyaltiesTax:tax.toString()});
      this.setData({fantuiRoyaltiesRate:"10"});
      this.setData({fantuiSusuanNum:"210"});
      return;
    }
    if(InputValue > 21428.57 && InputValue <= 44642.86){
      var before = (InputValue - 1410 ) / (1 - 0.112);
      before = before.toFixed(2);
      this.setData({fantuiRoyaltiesBeforeRate:before.toString()});
      var tax = (before - InputValue).toFixed(2);
      this.setData({fantuiRoyaltiesTax:tax.toString()});
      this.setData({fantuiRoyaltiesRate:"20"});
      this.setData({fantuiSusuanNum:"1410"});
      return;
    }
    if(InputValue > 44642.86 && InputValue <= 62500){
      var before = (InputValue - 2660 ) / (1 - 0.14);
      before = before.toFixed(2);
      this.setData({fantuiRoyaltiesBeforeRate:before.toString()});
      var tax = (before - InputValue).toFixed(2);
      this.setData({fantuiRoyaltiesTax:tax.toString()});
      this.setData({fantuiRoyaltiesRate:"25"});
      this.setData({fantuiSusuanNum:"2660"});
      return;
    }
    if(InputValue > 62500 && InputValue <= 98214.29){
      var before = (InputValue - 4410 ) / (1 - 0.168);
      before = before.toFixed(2);
      this.setData({fantuiRoyaltiesBeforeRate:before.toString()});
      var tax = (before - InputValue).toFixed(2);
      this.setData({fantuiRoyaltiesTax:tax.toString()});
      this.setData({fantuiRoyaltiesRate:"30"});
      this.setData({fantuiSusuanNum:"4410"});
      return;
    }
    if(InputValue > 98214.29 && InputValue <= 142857.14){
      var before = (InputValue - 7160 ) / (1 - 0.196);
      before = before.toFixed(2);
      this.setData({fantuiRoyaltiesBeforeRate:before.toString()});
      var tax = (before - InputValue).toFixed(2);
      this.setData({fantuiRoyaltiesTax:tax.toString()});
      this.setData({fantuiRoyaltiesRate:"35"});
      this.setData({fantuiSusuanNum:"7160"});
      return;
    }else{
      var before = ( InputValue - 15160 ) / (1 - 0.252);
      before = before.toFixed(2);
      this.setData({fantuiRoyaltiesBeforeRate:before.toString()});
      var tax = (before - InputValue).toFixed(2);
      this.setData({fantuiRoyaltiesTax:tax.toString()});
      this.setData({fantuiRoyaltiesRate:"45"});
      this.setData({fantuiSusuanNum:"15160"});
      return;
    }
  },

  // 计算反推的税前稿酬
  calaculateFantuiRoyalties(e){
    var value = e.detail.value;
    if(/^(0|[1-9][0-9]*)$/.test(value) || /^([1-9][0-9]*\.)$/.test(value) || /^([1-9][0-9]*)+(\.[0-9]{1,2})?$/.test(value)){
      var income = Number.parseFloat(value);
      var type = this.data.fantuiRoyaltiesCalWay;
      if(type == "1"){
        // 计算居民劳务收入
        this.calJuMingFantuiRoyalties(income);
      }else{
        // 计算非居民劳务收入
        this.calFeiJuMingFantuiRoyalties(income);
      }
    }else{
      wx.showToast({
        title: '请正确输入税后收入！\r\n(仅数字，最多2位小数)',
        icon:'none'
      });
      this.setData({fantuiRoyaltiesRate:"20"});
      this.setData({fantuiRoyaltiesTax:"0.00"});
      this.setData({fantuiSusuanNum:"0"});
      this.setData({fantuiRoyaltiesTax:"0.00"});
      this.setData({royaltiesFantui:''});
      return;
   }
  },

  // 再次点击输入框后的清除功能
  clearInputFantuiRoyalties(e){
    this.setData({royaltiesFantui:''});
    this.setData({fantuiRoyaltiesBeforeRate:"0.00"});
    this.setData({fantuiRoyaltiesRate:"20"});
    this.setData({fantuiSusuanNum:0});
    this.setData({fantuiRoyaltiesTax:"0.00"});
  },

  // 单击输入框清空当前输入
  clearInputRoyalties(e){
    this.setData({royalties:''});
    this.setData({royaltiesAfterRate:"0.00"});
    this.setData({royaltiesRate:"20"});
    this.setData({sunsuanForRoyalties:0});
    this.setData({royaltiesTax:"0.00"});
  },
/***************特许权使用费，计算方式与稿酬一模一样，目前为了省时间直接抄之前的函数了，懒得重写了 **** */

onGetFranchiseCalWay(e){
  this.setData({franchiseCalWay:e.detail.value});
},

onGetFantuiFranchiseCalWay(e){
  this.setData({fantuiFranchiseCalWay:e.detail.value});
},

calFantuiJuMingFranchise:function(InputValue){
  if(InputValue <= 800){
    this.setData({fantuiFranchiseBeforeRate:InputValue.toString()});
    this.setData({fantuiFranchiseTax:"0.00"});
    this.setData({fantuiFranchiseRate:"20"});
    this.setData({fantuiFranchiseSusuanNum:"0"});
    return;
  }
  //小于4000的减除费用为800，税率20%
  if(InputValue <= 3360 && InputValue > 800){
    var before = (InputValue - 160) / 0.8;
    before = before.toFixed(2);
    this.setData({fantuiFranchiseBeforeRate:before.toString()});
    var tax = (before - InputValue).toFixed(2);
    this.setData({fantuiFranchiseTax:tax.toString()});
    this.setData({fantuiFranchiseRate:"20"});
    this.setData({fantuiFranchiseSusuanNum:"0"});
    return;
  }
  //大于4000，速算扣除0，减除费用20%，税率20%
  else{
    var before = InputValue / 0.84
    before = before.toFixed(2);
    this.setData({fantuiFranchiseBeforeRate:before.toString()});
    var tax = (before - InputValue).toFixed(2);
    this.setData({fantuiFranchiseTax:tax.toString()});
    this.setData({fantuiFranchiseRate:"20"});
    this.setData({fantuiFranchiseSusuanNum:"0"});
    return;
  }
},

calFantuiFeiJuMingFranchise:function(InputValue){
  if(InputValue <= 3750){
    var before = InputValue / 0.976;
    before = before.toFixed(2);
    this.setData({fantuiFranchiseBeforeRate:before.toString()});
    var tax = (before - InputValue).toFixed(2);
    this.setData({fantuiFranchiseTax:tax.toString()});
    this.setData({fantuiFranchiseRate:"3"});
    this.setData({fantuiFranchiseSusuanNum:"0"});
    return;
  }
  if(InputValue > 3750 && InputValue <= 15000){
    var before = (InputValue - 210 ) / 0.92;
    before = before.toFixed(2);
    this.setData({fantuiFranchiseBeforeRate:before.toString()});
    var tax = (before - InputValue).toFixed(2);
    this.setData({fantuiFranchiseTax:tax.toString()});
    this.setData({fantuiFranchiseRate:"10"});
    this.setData({fantuiFranchiseSusuanNum:"210"});
    return;
  }
  if(InputValue > 15000 && InputValue <= 31250){
    var before = (InputValue - 1410 ) / 0.84;
    before = before.toFixed(2);
    this.setData({fantuiFranchiseBeforeRate:before.toString()});
    var tax = (before - InputValue).toFixed(2);
    this.setData({fantuiFranchiseTax:tax.toString()});
    this.setData({fantuiFranchiseRate:"20"});
    this.setData({fantuiFranchiseSusuanNum:"1410"});
    return;
  }
  if(InputValue > 31250 && InputValue <= 43750){
    var before = (InputValue - 2660 ) / 0.8;
    before = before.toFixed(2);
    this.setData({fantuiFranchiseBeforeRate:before.toString()});
    var tax = (before - InputValue).toFixed(2);
    this.setData({fantuiFranchiseTax:tax.toString()});
    this.setData({fantuiFranchiseRate:"25"});
    this.setData({fantuiFranchiseSusuanNum:"2660"});
    return;
  }
  if(InputValue > 43750 && InputValue <= 68750){
    var before = (InputValue - 4410 ) / 0.76;
    before = before.toFixed(2);
    this.setData({fantuiFranchiseBeforeRate:before.toString()});
    var tax = (before - InputValue).toFixed(2);
    this.setData({fantuiFranchiseTax:tax.toString()});
    this.setData({fantuiFranchiseRate:"30"});
    this.setData({fantuiFranchiseSusuanNum:"4410"});
    return;
  }
  if(InputValue > 68750 && InputValue <= 100000){
    var before = (InputValue - 7160 ) / 0.72;
    before = before.toFixed(2);
    this.setData({fantuiFranchiseBeforeRate:before.toString()});
    var tax = (before - InputValue).toFixed(2);
    this.setData({fantuiFranchiseTax:tax.toString()});
    this.setData({fantuiFranchiseRate:"35"});
    this.setData({fantuiFranchiseSusuanNum:"7160"});
    return;
  }else{
    var before = ( InputValue - 15160 ) / 0.64;
    before = before.toFixed(2);
    this.setData({fantuiFranchiseBeforeRate:before.toString()});
    var tax = (before - InputValue).toFixed(2);
    this.setData({fantuiFranchiseTax:tax.toString()});
    this.setData({fantuiFranchiseRate:"45"});
    this.setData({fantuiFranchiseSusuanNum:"15160"});
    return;
  }
},



clearInputFranchise(e){
  this.setData({franchise:''});
  this.setData({franchiseAfterRate:"0.00"});
  this.setData({franchiseRate:"20"});
  this.setData({sunsuanForfranchise:0});
  this.setData({franchiseTax:"0.00"});
},

calFeiJuMingFranchise:function(input){
   // 特许权使用费没有减按70%这个规定
   var baochou = input * 0.8;
   var tax = 0
   if(baochou <= 3000){
       this.setData({sunsuanForFranchise:"0"});
       this.setData({franchiseRate:"3"});
       tax = (baochou * 0.03).toFixed(2) ;
       //console.log(this.data.laowutax);   
   }
   else if(baochou > 3000 && baochou <= 12000){
       this.setData({sunsuanForFranchise:"210"});
       this.setData({franchiseRate:"10"});
       tax = (baochou * 0.1 - 210).toFixed(2) ;
       // console.log(this.data.laowutax);
   }
  else if(baochou > 12000 && baochou <= 25000){
       this.setData({sunsuanForFranchise:"1410"});
       this.setData({franchiseRate:"20"});
       tax = (baochou * 0.2 - 1410).toFixed(2);
       // console.log(this.data.laowutax);
   }
  else if(baochou > 25000 && baochou <= 35000){
       this.setData({sunsuanForFranchise:"2660"});
       this.setData({franchiseRate:"25"});
      tax = (baochou * 0.25 - 2660).toFixed(2);
   }
   else if(baochou > 35000 && baochou <= 55000){
     this.setData({sunsuanForFranchise:"4410"});
     this.setData({franchiseRate:"30"});
     tax = (baochou * 0.3 - 4410).toFixed(2);
   }
   else if(baochou > 55000 && baochou <= 80000){
     this.setData({sunsuanForFranchise:"7160"});
     this.setData({franchiseRate:"35"});
     tax = (baochou * 0.35 - 7160).toFixed(2);
   }
   else{
     this.setData({sunsuanForFranchise:"15160"});
     this.setData({franchiseRate:"45"});
     tax = (baochou * 0.45 - 15160).toFixed(2);
   }
   this.setData({franchiseTax:tax.toString()});
     // console.log(this.data.laowutax);
   return;
},

clearInputFantuiFranchise(e){
  this.setData({franchiseFantui:''});
  this.setData({fantuiFranchiseBeforeRate:"0.00"});
  this.setData({fantuiFranchiseRate:"20"});
  this.setData({fantuiFranchiseSusuanNum:0});
  this.setData({fantuiFranchiseTax:"0.00"});
},

calJuMingFranchise:function(input){
  var tempValue = input;
  if(input <= 4000){
    tempValue = tempValue - 800;
    if(tempValue <= 0){
      this.setData({franchiseTax:"0.00"});
      this.setData({franchiseAfterRate:input.toString()});
      return;
    }else{
      // 特许权使用费预扣预缴税率20%
      var tax = (tempValue * 0.2).toFixed(2);
      this.setData({franchiseTax:tax.toString()});
      return;
    }
  }else{
    var tax = (tempValue * 0.8 * 0.2).toFixed(2);
    this.setData({franchiseTax:tax.toString()});
    return;
  }
},

calculateFantuiJuMingFranchise:function(input){
  var InputValue = input;
  if(InputValue <= 800){
    this.setData({fantuiRoyaltiesBeforeRate:InputValue.toString()});
    this.setData({fantuiFranchiseTax:"0.00"});
    this.setData({fantuiFranchiseRate:"20"});
    this.setData({fantuiSusuanNum:"0"});
    return;
  }
  //小于4000的减除费用为800，税率20%
  if(InputValue <= 7142.86 && InputValue > 800){
    var before = (InputValue - 112) / 0.86;
    before = before.toFixed(2);
    this.setData({fantuiRoyaltiesBeforeRate:before.toString()});
    var tax = (before - InputValue).toFixed(2);
    this.setData({fantuiFranchiseTax:tax.toString()});
    this.setData({fantuiFranchiseRate:"20"});
    this.setData({fantuiSusuanNum:"0"});
    return;
  }
  //大于4000，速算扣除0，减除费用20%，减按70%，税率20%
  else{
    var before = InputValue / (1 - 0.112)
    before = before.toFixed(2);
    this.setData({fantuiFranchiseBeforeRate:before.toString()});
    var tax = (before - InputValue).toFixed(2);
    this.setData({fantuiFranchiseTax:tax.toString()});
    this.setData({fantuiFranchiseRate:"20"});
    this.setData({fantuiSusuanNum:"0"});
    this.setData({franchiseFantui:''})
    return;
  }
},

onGetFranchiseAfterRate(e){
  var value = e.detail.value;
  if(/^(0|[1-9][0-9]*)$/.test(value) || /^([1-9][0-9]*\.)$/.test(value) || /^([1-9][0-9]*)+(\.[0-9]{1,2})?$/.test(value)){
    this.setData({franchise:value});
    var input = Number.parseFloat(value);
    var type = this.data.franchiseCalWay;
    if(type == "1"){
      // 计算居民劳务收入
      this.calJuMingFranchise(input);
    }else{
      // 计算非居民劳务收入
      this.calFeiJuMingFranchise(input);
    }
    var shuiHou = (input - this.data.franchiseTax).toFixed(2);
    this.setData({franchiseAfterRate:shuiHou.toString()});
    console.log("税后稿酬"+this.data.franchiseAfterRate)
  }else{
     wx.showToast({
       title: '请正确输入税前收入！\r\n(仅数字，最多2位小数)',
       icon:'none'
     });
     this.setData({franchiseAfterRate:"0.00"});
     this.setData({franchiseTax:"0.00"}); 
     this.setData({franchise:''});
     this.setData({sunsuanForFranchise:"0"});
     this.setData({franchiseRate:"20"});
     return;
  }
},

onGetFantuiFranchise(e){
  var value = e.detail.value;
    if(/^(0|[1-9][0-9]*)$/.test(value) || /^([1-9][0-9]*\.)$/.test(value) || /^([1-9][0-9]*)+(\.[0-9]{1,2})?$/.test(value)){
      var income = Number.parseFloat(value);
      var type = this.data.fantuiFranchiseCalWay;
      if(type == "1"){
        // 计算居民劳务收入
        this.calFantuiJuMingFranchise(income);
      }else{
        // 计算非居民劳务收入
        this.calFantuiFeiJuMingFranchise(income);
      }
    }else{
      wx.showToast({
        title: '请正确输入税后收入！\r\n(仅数字，最多2位小数)',
        icon:'none'
      });
      this.setData({fantuiFranchiseRate:"20"});
      this.setData({fantuiFranchiseTax:"0.00"});
      this.setData({fantuiFranchiseSusuanNum:"0"});
      this.setData({fantuiFranchiseBeforeRate:"0.00"});
      this.setData({fantuiFranchise:''});
      return;
   }
},

/********************************all end******************************************** */
  clearAllStorage:function(e){
    wx.showModal({
      title: '提示',
      content: '缓存清空后，之前的填写记录将丢失，是否清空？',
      success (res) {
        if (res.confirm) {
          try {
            wx.clearStorageSync();
            wx.showToast({  
              title: '清理完成!', // 提示的内容  
              icon: 'sucess' // 图标，成功时显示对号图标  
            }, 4000);
          } catch(e) {
            console.log(e);
          }
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    });
  },

  calculate(e){
    var month = this.data.calDate;
    var year = this.data.calYear
    var tabIndex = this.data.activeVantTab;
    //说明用户都没选计算月份就开始填写了
    if(month.indexOf('-') === -1 && tabIndex === 0){
      wx.showToast({  
        title: '请选择计算月份!', // 提示的内容  
        icon: 'error' // 图标，成功时显示对号图标  
      });
      return;
    }
    if(year.length > 4 && tabIndex === 1){
      wx.showToast({  
        title: '请选择计算年份!', // 提示的内容  
        icon: 'error' // 图标，成功时显示对号图标  
      });
      return;
    }
    this.setData({
      loadingHidden: false
    });
    var that = this;
    setTimeout(function(){
     that.setData({
         loadingHidden: true
        });
   },1000);
   if(tabIndex === 0){
    wx.navigateTo({
      url: '/pages/result/result?calDate='+this.data.calDate
    });
   }else{
    const annualBaochou = JSON.stringify(this.data.annualBaochou);
    const annualFranchise = JSON.stringify(this.data.annualFranchise);
    const annualRoyalties = JSON.stringify(this.data.annualRoyalties);
    const yearEndBonus = JSON.stringify(this.data.yearEndBonus);
    const annualSalary = JSON.stringify(this.data.annualSalary);
    const annualSecurate = JSON.stringify(this.data.annualSecurate);
    const annualGongjijing = JSON.stringify(this.data.annualGongjijing);
    const annualZhuanXiang = JSON.stringify(this.data.annualZhuanXiang);
    const annualAnother = JSON.stringify(this.data.annualAnother);
    const yearEndBonusWayChange = JSON.stringify(this.data.yearEndBonusWayChange);
    try {
      wx.setStorageSync("annualBaochou",annualBaochou);
      wx.setStorageSync("annualFranchise",annualFranchise);
      wx.setStorageSync("annualRoyalties",annualRoyalties);
      wx.setStorageSync("yearEndBonus",yearEndBonus);
      wx.setStorageSync("annualSalary",annualSalary);
      wx.setStorageSync("yearEndBonusWayChange",yearEndBonusWayChange);
      wx.setStorageSync("annualSecurate",annualSecurate);
      wx.setStorageSync("annualGongjijing",annualGongjijing);
      wx.setStorageSync("annualZhuanXiang",annualZhuanXiang);
      wx.setStorageSync("annualAnother",annualAnother);
    } catch (e) { 
      console.log(e);
    }
    wx.navigateTo({
      url: '/pages/result_year/result_year?calYear='+year
    });
   }
    
  },

  navTab(e) {
    let {
      index
    } = e.currentTarget.dataset;
    if (this.data.type === index || index === undefined) {
      return false;
    } else {
      this.setData({
        nav_type: index,
      })
    }
  },
  /** 
 * 生命周期函数--监听页面加载 
 */ 
  pop(){
    console.log('点击了我');
  },

 onLoad: function (options) { 
  wx.showShareMenu({
    withShareTicket:true,
    menus:["shareAppMessage",'shareTimeline']});
  var that = this; 
  const date = new Date();
  const formattedDate = util.formatTime(date);
  // console.log(formattedDate); // 输出：当前日期
  var year = formattedDate.split("/");
  that.setData({nowYear:year[0]});
  console.log(formattedDate); 
  /** 
  * 获取系统信息 
  */ 
  const windowInfo = wx.getWindowInfo();
  this.setData({winWidth:windowInfo.windowWidth,winHeight:windowInfo.windowHeight-20})
    try {
      var value = wx.getStorageSync("annualBaochou");
        if(value){
        that.setData({annualBaochou:JSON.parse(value)});
        }
        value = wx.getStorageSync("annualFranchise");
        if(value){
        that.setData({annualFranchise:JSON.parse(value)});
        }
        value = wx.getStorageSync("annualRoyalties");
        if(value){
        that.setData({annualRoyalties:JSON.parse(value)});
        }
        value = wx.getStorageSync("yearEndBonus");
        if(value){
        that.setData({yearEndBonus:JSON.parse(value)});
        }
        value = wx.getStorageSync("annualSalary");
        if(value){
        that.setData({annualSalary:JSON.parse(value)});
        }
        value = wx.getStorageSync("yearEndBonusWayChange");
        if(value){
        that.setData({yearEndBonusWayChange:JSON.parse(value)});
        }
        value = wx.getStorageSync("annualSecurate");
        if(value){
          that.setData({annualSecurate:JSON.parse(value)});
          }
        value = wx.getStorageSync("annualGongjijing");
        if(value){
          that.setData({annualGongjijing:JSON.parse(value)});
          }
        value = wx.getStorageSync("annualZhuanXiang");
        if(value){
          that.setData({annualZhuanXiang:JSON.parse(value)});
          }
        value = wx.getStorageSync("annualAnother");
        if(value){
          that.setData({annualAnother:JSON.parse(value)});
        }
    } catch (e) {
      console.log(e)
    }
  }, 
  
  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },

  onShareAppMessage() {
    return {
      title: '答哥算税计算器',
      path: '/pages/index/index'
    }
  }
})
